package com.vincent.suchao.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vincent.suchao.entity.NineMenuItem;
import com.vincent.suchao.entity.NineMenus;
import com.vincent.suchao.lcld.R;

public class NineMenuAdapter extends BaseAdapter {
	private ArrayList<Bitmap> myBitmaps;

	private Context context;
	private LayoutInflater mInflater;
	NineMenus nineMenus;

	public NineMenuAdapter(Context mcontext) {
		super();
		this.context = mcontext;
		this.mInflater = LayoutInflater.from(context);
		this.nineMenus = new NineMenus(mcontext);
	}

	@Override
	public int getCount() {
		return nineMenus.getNineMenus().size();
	}

	@Override
	public Object getItem(int position) {
		return nineMenus.getNineMenus().get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		NineMenuItem menuItem = (NineMenuItem) nineMenus.getNineMenus().get(
				position);

		MyHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.inflater_gridview_menu,
					null);
			holder = new MyHolder();

			holder.rl_inflate_menu = (RelativeLayout) convertView
					.findViewById(R.id.rl_inflate_menu);
			holder.iv_menu = (ImageView) convertView.findViewById(R.id.iv_menu);
			holder.tv_menu = (TextView) convertView.findViewById(R.id.tv_menu);

			convertView.setTag(holder);
		} else {
			holder = (MyHolder) convertView.getTag();
		}
		holder.rl_inflate_menu.setTag(R.id.rl_inflate_menu, menuItem);
		holder.iv_menu.setImageResource(menuItem.getResID());
		holder.tv_menu.setText(menuItem.getMenuName());

		return convertView;
	}

	class MyHolder {
		RelativeLayout rl_inflate_menu;
		ImageView iv_menu;
		TextView tv_menu;

	}

}
